package com.douwong.student.base;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.douwong.student.enums.E_CommandType;
import com.douwong.student.model.ExamResult;
import com.douwong.student.model.TcpPacket;

import java.util.List;

import rx.Subscription;

/**
 * @autor yichao
 * @time 2017/3/2214:56
 * @des ${TODO}
 */
@SuppressLint("ValidFragment")
public abstract class BaseFragment extends Fragment {
    protected Subscription subscription;
    @SuppressWarnings("unchecked")
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View viewRoot=getRootView(inflater,container);
        initData();
        initEvent();
        return viewRoot;

    }
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unsubscribe();

    }
protected void unsubscribe(){
    if (subscription!=null &&!subscription.isUnsubscribed()){
        subscription.unsubscribe();
    }
}
    /**
     * 初始化事件
     */
    protected void initEvent() {
    }

    /**
     * 初始化数据
     */
    protected void initData() {
    }

    /**
     *  初始化根布局
     * @param inflater
     * @param container
     * @return
     */
    protected abstract View getRootView(LayoutInflater inflater, ViewGroup container);

    /**
     * frgagment处理长连接消息
     * @param tcpPacket
     * @param commandType
     */
    public void handleLongMsg(TcpPacket tcpPacket, E_CommandType commandType){};

    /**
     * 设置学生作答结果
     * @param examResultList
     */
    public void setExamResultList(List<ExamResult> examResultList){};


}
